package com.jackiechan.day12;

import java.io.*;


// FileInputStream 和 BufferedInputStream 的区别
// BufferedInputStream 底层维护了一个byte[] buf
// 默认容量是8192,不像FileInputStream一个字节一个字节的读取
// BufferedInputStream 是一个数组一个数组的读取
public class Test_InStream {
    public static void main(String[] args) throws IOException {
        method();
        method1();
    }
    public static void method() throws IOException {
//        File file = new File("D:\\test\\1.txt");
//        FileInputStream input = new FileInputStream(file);
//        byte[] b = new byte[15];
//        int i = input.read(b);
//        System.out.println(i);
//        System.out.println(Arrays.toString(b));
//        input.close();
        InputStream input1 = new FileInputStream("D:\\test\\1.txt");
        int b1=0;
        double start = System.nanoTime();
        while ((b1=input1.read())!=-1){
            System.out.print(b1+" ");
        }
        double end = System.nanoTime();
        System.out.println("耗时:"+(end-start)/1000000+"毫秒");
        input1.close();
    }

    public static void method1() throws IOException{
        InputStream  bin = new BufferedInputStream(
                new FileInputStream(
                        new File("D:\\test\\1.txt")));
        int b=0;
        double start = System.nanoTime();
        while((b=bin.read()) != -1){
            System.out.print(b+" ");
        }
        double end = System.nanoTime();
        System.out.println("耗时:"+(end-start)/1000000+"毫秒");
        bin.close();
    }

}
